<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="num++">点击修改数值</button>
        <h2>{{num}}</h2>
        <hr><br>
        <input type="text" v-model="goodData.name">
        <input type="text" v-model="goodData.age">
        <input type="text" v-model="goodData.sex">
        <input type="text" v-model="goodData.hobby">
    </div>
    <script>
        const vm = new Vue({
            data(){
                return{
                    num:10,
                    goodData:{
                        name:"张三",
                        age:"18",
                        sex:"男",
                        hobby:"敲代码"
                    }
                }
            },
            watch:{
                num(vale,oldValue){ //监听简单数据
                    console.log("更新num",vale,oldValue);
                },
                "goodData.name"(vale,oldValue){ //监听对象上的某一个属性
                    console.log("更新goodData.name",vale,oldValue);
                },
                goodData:{
                    immediate: true, //初始化就渲染
                    deep:true, //深度监听
                    handler(value,oldValue){
                        console.log("更改goodData",value,oldValue);
                    }
                }
            }
        }).$mount("#app")
    </script>
</body>

</html>